package com.you.place.dal.dao;

import java.util.Map;

import org.apache.commons.collections.map.HashedMap;

import com.you.common.ibatis.AbstractDAO;
import com.you.common.ibatis.data.DataList;
import com.you.common.ibatis.param.QueryParam;
import com.you.place.dal.dao.dataobject.SmallNoteDO;

public class SmallNoteDAO extends AbstractDAO {

    public Long create(SmallNoteDO smallNoteDO) {
        return (Long) super.getSqlMapClientTemplate().insert("MS-INSERT-SMALLNOTE", smallNoteDO);
    }

    public DataList queryByTime(Long placeId, int pageNo, int pageSize) {
        return querySmallNote(placeId, pageNo, pageSize, "time");
    }

    public DataList queryByUseFul(Long placeId, int pageNo, int pageSize) {
        return querySmallNote(placeId, pageNo, pageSize, "useful");
    }

    public int updateUsefulCount(Long id) {

        return getSqlMapClientTemplate().update("MS-UPDATE-USEFUL-COUNT", id);
    }

    private DataList querySmallNote(Long placeId, int pageNo, int pageSize, String orderType) {
        QueryParam<String, Object> queryParam = new QueryParam<String, Object>();
        queryParam.setPageNo(pageNo);
        queryParam.setPageSize(pageSize);
        queryParam.put("placeId", placeId);
        queryParam.put("orderType", orderType);
        return super.getSqlMapClientTemplate().pagedQuery(queryParam, "MS-SELECT-SMALL-NOTE-BY-PLACE-ID");
    }

    public int delete(Long id, Long memberId) {
        Map param = new HashedMap();
        param.put("id", id);
        param.put("memberId", memberId);
        return super.getSqlMapClientTemplate().delete("MS-DELETE-SMALL-NOTE-BY-ID", param);
    }
}
